import { getToken } from '@/utils/storage';
export type UserInfo = {
  id: string;
  name: string;
  photo: string;
  art_count: number;
  follow_count: number;
  fans_count: number;
  like_count: number;
};

export type Auth = {
  token: string;
  refresh_token: string;
};
const initialState = {
  profile: {} as ProfileInfo,
  user: {} as UserInfo,
  auth: getToken(),
};

export type ProfileInfo = {
  id: string;
  photo: string;
  name: string;
  mobile: string;
  gender: number;
  birthday: string;
  intro?: string;
};

type UserAction =
  | { type: 'user/saveAuthor'; payload: Auth }
  | { type: 'user/saveUserInfo'; payload: UserInfo }
  | { type: 'user/saveProfile'; payload: ProfileInfo };

export default function userReducer(state = initialState, action: UserAction) {
  switch (action.type) {
    case 'user/saveAuthor':
      return {
        ...state,
        auth: action.payload,
      };
    case 'user/saveUserInfo':
      return {
        ...state,
        user: action.payload,
      };
    case 'user/saveProfile':
      return {
        ...state,
        profile: action.payload,
      };
    default:
      return state;
  }
}
